package com.analog.mserver.controller.video;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.analog.mserver.common.RestResult;
import com.analog.mserver.service.upload.UploadService;
import com.analog.mserver.vo.file.VideoVO;

import io.swagger.annotations.Api;

@RestController
@Api("UploadController相关的api")
@RequestMapping("/upload")
@RefreshScope
public class UploadController {

	@Autowired
	private UploadService uploadService;
	
	@PostMapping("/video")
	public RestResult video(@RequestParam("file") MultipartFile file) {
		if (file.isEmpty()) {
            return new RestResult("文件不能为空");
        }
		if(uploadService.uploadVideo(file)) {
			return new RestResult("上传成功");
		}else {
			return new RestResult("上传失败");
		}
	}
	
	
	
	@PostMapping("/video/list")
	public RestResult videoList(@RequestBody VideoVO vo) {
		return new RestResult(uploadService.findVideoPage(vo));
	}
	
	@DeleteMapping("/video/del")
	public RestResult videoDel(@RequestBody String[] ids) {
		return new RestResult(uploadService.videoDel(ids));
	}
	
	
	 /**
	  * 获取文件上传进度
     * @param request
     * @return
     */
    @GetMapping("/getUploadProgress")
    public RestResult getUploadProgress(HttpSession session){
        return new RestResult(session.getAttribute("uploadStatus")); 
    }
}
